package com.dj.mingkong.portal.biz.controller.music;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dj.mingkong.common.annotation.RequestLimit;
import com.dj.mingkong.common.infrastructure.base.dto.page.PageVo;
import com.dj.mingkong.common.infrastructure.base.dto.rest.RestResponse;
import com.dj.mingkong.common.microservice.UserContext;
import com.dj.mingkong.common.util.AssertUtils;
import com.dj.mingkong.common.util.SmartBeanCopy;
import com.dj.mingkong.portal.biz.controller.music.vo.request.MusicianVisitAddVo;
import com.dj.mingkong.portal.biz.controller.music.vo.request.MusicianVisitCancelVo;
import com.dj.mingkong.portal.biz.controller.music.vo.request.MusicianVisitQueryVo;
import com.dj.mingkong.portal.biz.controller.music.vo.request.MusicianVisitUserQueryVo;
import com.dj.mingkong.portal.biz.controller.music.vo.response.MusicianVisitUserVo;
import com.dj.mingkong.portal.biz.controller.music.vo.response.MusicianVisitVo;
import com.dj.mingkong.portal.biz.service.music.MusicianVisitService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 音乐人访客管理
 *
 * @author zenglonghui
 * @date: 2022/8/23 10:57
 */
@RestController
@RequestMapping("/musician/visit")
public class MusicianVisitController {
    @Resource
    private MusicianVisitService musicianVisitService;

    /**
     * 新增音乐人访客与人气
     *
     * @param addVo 实例对象
     * @return 是否成功，true-成功，false-失败
     * @throws RuntimeException addPopularityVo.getId为空的时候会抛出运行时异常
     */
    @PostMapping("/add")
    public RestResponse<Boolean> add(@RequestBody @Validated MusicianVisitAddVo addVo) {
        musicianVisitService.add(addVo);
        return RestResponse.buildSuccess();
    }

    /**
     * 分页查询访问过的音乐人列表
     *
     * @param queryVo {}
     * @return MusicianVo
     */
    @PostMapping("/pageByVo")
    public RestResponse<PageVo<MusicianVisitVo>> pageByVo(@RequestBody MusicianVisitQueryVo queryVo) {
        AssertUtils.checkQueryPageVo(queryVo);
        queryVo.setUserId(UserContext.getUserId());
        final Page<MusicianVisitVo> musicianVisitVoPage = musicianVisitService.pageByVo(queryVo);
        final PageVo<MusicianVisitVo> pageVo = SmartBeanCopy.copyPageVo(musicianVisitVoPage, MusicianVisitVo.class);
        return RestResponse.success(pageVo);
    }

    /**
     * 获取谁看过我的用户列表
     *
     * @param queryVo {}
     * @return UserVisitVo
     */
    @PostMapping("/user/pageByVo")
    public RestResponse<PageVo<MusicianVisitUserVo>> pageUserByVo(@RequestBody @Validated MusicianVisitUserQueryVo queryVo) {
        AssertUtils.checkQueryPageVo(queryVo);
        queryVo.setUserId(UserContext.getUserId());
        final Page<MusicianVisitUserVo> userVisitVoPage = musicianVisitService.pageUserByVo(queryVo);
        final PageVo<MusicianVisitUserVo> pageVo = SmartBeanCopy.copyPageVo(userVisitVoPage, MusicianVisitUserVo.class);
        return RestResponse.success(pageVo);
    }

    /**
     * 取消到访
     *
     * @param cancelVo {}
     * @return Boolean
     */
    @PostMapping("/cancel")
    @RequestLimit(count = 5)
    public RestResponse<Boolean> cancel(@RequestBody @Validated MusicianVisitCancelVo cancelVo) {
        musicianVisitService.cancel(cancelVo);
        return RestResponse.buildSuccess();
    }
}
